
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
analytics-id
Advanced tools
A tiny utility for working with analytics ids
on the server and in the browser.
Install with npm:
npm install --save analytics-id
Or with yarn:
yarn add analytics-id
import analyticsId from 'analytics-id'
// generate or pull id from cookie/localStorage
analyticsId()
// call the function with string or number to set as id, otherwise pass in options
analyticsId('exampleId')
import { get, set } from 'analytics-id'
set({ key: 'my_anon_id' }) // ajs-C1E42A94-FCE2-4851-87DD-695F576C5368 -> cookie or localStorage
get({ key: 'my_anon_id' }) // cookie or localStorage -> ajs-C1E42A94-FCE2-4851-87DD-695F576C5368
These are the base options that can be passed in to both get and set functions:
analyticsId({
debug: true, // log operations to stdout
preset: String, // prefix/generateId/stores to use
cookie: String, // cookie string to use (browser default is document.cookie)
localStorage: Object // Storage object to use (browser default is window.localStorage)
})
For setting analytics ids, you can specify an id
field which will pass the options to setAnalyticsId()
. If you don't set the id
option, then getAnalyticsId()
will be called with the options:
const id = await promptEmailFromUser()
analyticsId({ id })
And for getting analytics ids, you can pass control if the preset tries to persist data:
console.log(document.cookie) // 'a=true'
const { cookie } = analyticsId({ persist: false })
console.log(document.cookie) // 'a=true'
console.log(cookie) // 'a=true; session_id=ajs-B31C9E91-D741-4146-913B-0E80199648D0'
All contributions are super welcome! analytics-id
is MIT-licensed.
FAQs
get and set analytics ids on the server and in the browser
The npm package analytics-id receives a total of 0 weekly downloads. As such, analytics-id popularity was classified as not popular.
We found that analytics-id demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.